package top.rainbowecho.ai.domain.model.robot.strategy.impl;

import org.springframework.stereotype.Component;
import top.rainbowecho.ai.domain.model.robot.AiRobot;
import top.rainbowecho.ai.domain.model.robot.strategy.SensitiveImageRecognizeStrategy;
import top.rainbowecho.ai.domain.model.robot.value.image.SensitiveImageListItem;
import top.rainbowecho.common.domain.shared.vo.SensitiveRecognizeResult;
import top.rainbowecho.common.util.ExceptionMessageContent;

import java.util.List;

/**
 * @author rainbow
 * @since 2019/11/29 15:10
 */
@Component(AiRobot.PORN_STRATEGY)
public class PornImageRecognizeStrategy implements SensitiveImageRecognizeStrategy {
    /**
     * 根据腾讯AI接口的图片鉴别接口响应结果进行识别
     *
     * @param reply 接口响应结果
     * @return 识别结果
     */
    @Override
    public SensitiveRecognizeResult recognize(List<SensitiveImageListItem> reply) {
        // 识别结果对应的标签
        String label;

        // 如果porn标签的置信度大于83，则认为是色情图片
        int pornConfidence = reply.get(2).getTag_confidence();
        boolean sensitive = pornConfidence > 83;

        // 如果hot标签的置信度大于normal标签，则认为是性感图片
        int normalConfidence = reply.get(0).getTag_confidence();
        int hotConfidence = reply.get(1).getTag_confidence();
        boolean hot = hotConfidence > normalConfidence;

        if (sensitive) {
            label = ExceptionMessageContent.PORN;
        } else if (hot){
            label = ExceptionMessageContent.HOT;
        } else {
            label  = ExceptionMessageContent.NORMAL;
        }

        // 色情和性感图片都视为敏感图片
        return new SensitiveRecognizeResult(sensitive || hot, label);
    }
}
